package com.example.demo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RestController
@RequestMapping("/request")
public class BlogCookieSessionController {
    @RequestMapping("/getCookie")
    public String getCookie(@CookieValue("username") String cookie){
        return "获取到Cookie:" + cookie;
    }
    @RequestMapping("/setSession")
    public String setSession(HttpSession session){
        session.setAttribute("username", "admin");
        return "设置username成功";
    }
    @RequestMapping("/getSession")
    public String getSession(@SessionAttribute("username") String username){
        return "从session中获取username:" + username;
    }
}
